package com.nciae.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SendMessageUtils {

    /**
     * 发送6位验证码给指定的手机号
     * @param phoneId
     * @return
     */
    public static String sendMessage(String phoneId,String code) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4FhJBF83KEW9YshhDfzT", "NZzrFCAakTOIzS6eZ28fOAK07zH19x");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phoneId);
        request.putQueryParameter("SignName", "阿宸体检");
        request.putQueryParameter("TemplateCode", "SMS_183793408");
        request.putQueryParameter("TemplateParam", "{ code : " + code + "}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            if ( ! response.getData().contains("OK")) {
                return "null";
            }
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return code;
    }

}
